package com.jx.lcs.customer.web;

import com.jx.lcs.customer.entity.Customer;
import com.jx.lcs.customer.service.CustomerService;
import com.tianyu.jty.common.persistence.Page;
import com.tianyu.jty.common.web.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/** 
 * 理财师controller
 * @author JiaYY 
 * @date 2015年7月2日
 */
@Controller
@RequestMapping("customer")
public class CustomerController extends BaseController {
	
	private static final Logger logger = LoggerFactory.getLogger(CustomerController.class);

	@Autowired
	private CustomerService customerService;
	
	/**
	 * 默认页面
	 */
	@RequestMapping(method = RequestMethod.GET)
	public String list() {
		return "customer/customerList";
	}
	
	/**
	 * 获取理财师列表json
	 */
	@RequestMapping(value="json",method = RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> customerList(HttpServletRequest request) {
		try{
			Page<Customer> page = getPage(request);
			page = customerService.findCustomerList(page, request);
			return getEasyUIData(page);
		}catch(Exception e){
			logger.error("--获取C端用户列表出现异常！", e);
			return null;
		}
	}
	/**
	 * 修改用户权限跳转
	 *
	 * @param id
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "update/{id}", method = RequestMethod.GET)
	public String updateForm(@PathVariable("id") String id, Model model) {
		model.addAttribute("userInfo", customerService.get(id));
		model.addAttribute("action", "update");
		return "Customer/customerForm";
	}
	/**
	 * 修改用户权限
	 *
	 * @param id
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "update", method = RequestMethod.POST)
	@ResponseBody
	public String update(HttpServletRequest request,Model model) {
		return "success";
	}
}
